package com.wulian.controller;

import com.google.rpc.Code;
import com.wulian.entities.Department;
import com.wulian.result.CodeStatus;
import com.wulian.result.ResponseResult;
import com.wulian.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author xf
 * @date 2021/3/24 下午 5:56
 * @Description
 */
@RestController
@RequestMapping("/department")
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;


    @GetMapping("/")
    public ResponseResult<List<Department>> getAll(){
        try {
            List<Department> departments = departmentService.getAll();
            if (departments!=null){
                return new ResponseResult<>(CodeStatus.OK,"查询成功",departments);
            }else {
                return new ResponseResult<>(CodeStatus.NOT_FOUND,"未查询到相关内容");
            }
        }catch (Exception e){
            return new ResponseResult<>(CodeStatus.FAIL,e.getMessage());
        }

    }
}
